package cn.lngaosu.lwyd.module.integration.dal.mysql.weixinarticle;

import java.util.*;

import cn.lngaosu.lwyd.framework.common.pojo.PageResult;
import cn.lngaosu.lwyd.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.lngaosu.lwyd.framework.mybatis.core.mapper.BaseMapperX;
import cn.lngaosu.lwyd.module.integration.dal.dataobject.weixinarticle.WeixinArticleDO;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.lngaosu.lwyd.module.integration.controller.admin.weixinarticle.vo.*;

/**
 * 微信文章 Mapper
 *
 * @author 张恒
 */
@Mapper
public interface WeixinArticleMapper extends BaseMapperX<WeixinArticleDO> {

    default PageResult<WeixinArticleDO> selectPage(WeixinArticlePageReqVO reqVO) {
        Long[] articleCreateTime = reqVO.getArticleCreateTime();
        Long[] articleCreateTimeList = null;
        if (ObjectUtils.isNotEmpty(articleCreateTime) && articleCreateTime.length == 2) {
            articleCreateTimeList = new Long[2];
            articleCreateTimeList[0] = articleCreateTime[0]/1000;
            articleCreateTimeList[1] = articleCreateTime[1]/1000;
        }

        Long[] articleUpdateTime = reqVO.getArticleUpdateTime();
        Long[] articleUpdateTimeList = null;
        if (ObjectUtils.isNotEmpty(articleUpdateTime) && articleUpdateTime.length == 2) {
            articleUpdateTimeList = new Long[2];
            articleUpdateTimeList[0] = articleUpdateTime[0]/1000;
            articleUpdateTimeList[1] = articleUpdateTime[1]/1000;
        }

        return selectPage(reqVO, new LambdaQueryWrapperX<WeixinArticleDO>()
                .betweenIfPresent(WeixinArticleDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(WeixinArticleDO::getArticleId, reqVO.getArticleId())
                .eqIfPresent(WeixinArticleDO::getTitle, reqVO.getTitle())
                .eqIfPresent(WeixinArticleDO::getAuthor, reqVO.getAuthor())
                .eqIfPresent(WeixinArticleDO::getDigest, reqVO.getDigest())
                .eqIfPresent(WeixinArticleDO::getContent, reqVO.getContent())
                .eqIfPresent(WeixinArticleDO::getContentSourceUrl, reqVO.getContentSourceUrl())
                .eqIfPresent(WeixinArticleDO::getThumbMediaId, reqVO.getThumbMediaId())
                .eqIfPresent(WeixinArticleDO::getShowCoverPic, reqVO.getShowCoverPic())
                .eqIfPresent(WeixinArticleDO::getNeedOpenComment, reqVO.getNeedOpenComment())
                .eqIfPresent(WeixinArticleDO::getOnlyFansCanComment, reqVO.getOnlyFansCanComment())
                .eqIfPresent(WeixinArticleDO::getUrl, reqVO.getUrl())
                .eqIfPresent(WeixinArticleDO::getIsDeleted, reqVO.getIsDeleted())
                .betweenIfPresent(WeixinArticleDO::getArticleCreateTime, articleCreateTimeList)
                .betweenIfPresent(WeixinArticleDO::getArticleUpdateTime, articleUpdateTimeList)
                .orderByAsc(WeixinArticleDO::getId));
    }

}